import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  },

  {
    path: '/layout',
    meta: {
      keepAlive: true
    },
    component: () => import('@/views/layout/index'),
    // children 表示子组件会渲染到父组件中
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index'),
        meta: {
          keepAlive: true
        }
      },
      {
        path: 'wenda',
        component: () => import('@/views/wenda/index')
      },
      {
        // children 中path 没添加/: http://localhost:9999/#/layout/vedio
        path: 'vedio',
        component: () => import('@/views/vedio/index')
      },
      {
        // children 中path 添加了/: http://localhost:9999/#/my
        path: '/my',
        component: () => import('@/views/my/index')
      }
    ]
  },
  {
    path: '/search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:art_id',
    component: () => import('@/views/article'),
    // 开启路径参数映射到组件的porps
    props: true
  },
  {
    path: '/updateProfile',
    component: () => import('@/views/profile/user-profile')
    // 开启路径参数映射到组件的porps
  }
]

const router = new VueRouter({
  routes
})

export default router
